﻿using DevExpress.XtraEditors;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.纳客;
using DXApplicationTangche.Utils.UC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.纳可
{
    public partial class Form纳客一览 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private List<SaleOrderFacadeDTO> saleOrderFacadeDTOs = new List<SaleOrderFacadeDTO>();
        private List<SaleOrderFacadeDTO> saleOrderFacadelist = new List<SaleOrderFacadeDTO>();
        private List<PaymentEntity> paymentEntitys = new List<PaymentEntity>();
        private List<SaleOrderFacadeBillEntryDTO> saleOrderFacadeBillEntryDTOs = new List<SaleOrderFacadeBillEntryDTO>();
        //  登录
        private String orgId { get; set; }
        public Form纳客一览()
        {
            InitializeComponent();
            this.refreshata();
        }
        private void refreshata()
        {
            if (!String.IsNullOrEmpty(this.orgId))
            {
                //  一览
                this.saleOrderFacadeDTOs = nakeService.getUnPushSaleOrderFacadeByOrgId(this.orgId);
                //  下推一览
                this.saleOrderFacadelist = nakeService.getPushSaleOrderFacadeByOrgId(this.orgId);
            }
            else {
                //  一览
                this.saleOrderFacadeDTOs = nakeService.getUnPushSaleOrderFacade();
                //  下推一览
                this.saleOrderFacadelist = nakeService.getPushSaleOrderFacade();
            }
            this.gridControl纳客一览.DataSource = this.saleOrderFacadeDTOs;
            this.gridView纳客一览.RefreshData();
            this.gridView销售出库.RefreshData();
            this.gridView支付方式.RefreshData();
            this.gridControl下推订单一览.DataSource = this.saleOrderFacadelist;
            this.gridView下推订单一览.RefreshData();
            this.gridView销售出库单.RefreshData();
            this.gridView支付.RefreshData();
        }

        private void 预览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String id = this.gridView纳客一览.GetRowCellValue(this.gridView纳客一览.FocusedRowHandle, "id").ToString();
                foreach (SaleOrderFacadeDTO item in this.saleOrderFacadeDTOs)
                {
                    if (id.Equals(item.id))
                    {
                        //    打开单条预览
                        Form纳客预览 Form纳客预览 = new Form纳客预览(item, false);
                        Form纳客预览.WindowState = FormWindowState.Maximized;
                        Form纳客预览.ShowDialog();
                        break;
                    }
                }
            }
            catch { }
            //  重新刷新
            this.refreshata();
        }

        private void 预览ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                String id = this.gridView下推订单一览.GetRowCellValue(this.gridView下推订单一览.FocusedRowHandle, "id").ToString();
                foreach (SaleOrderFacadeDTO item in this.saleOrderFacadelist)
                {
                    if (id.Equals(item.id))
                    {
                        //    打开单条预览
                        Form纳客预览 Form纳客预览 = new Form纳客预览(item, true);
                        Form纳客预览.WindowState = FormWindowState.Maximized;
                        Form纳客预览.ShowDialog();
                        break;
                    }
                }
            }
            catch { }
            //  重新刷新
            this.refreshata();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.refreshata();
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                String 用户 = this.barEditItem用户.EditValue.ToString();
                String 密码 = this.barEditItem密码.EditValue.ToString();
            }
            catch
            {
                MessageBox.Show("用户名密码不能为空");
                return;
            }
            try
            {
                if (!String.IsNullOrWhiteSpace(this.barEditItem用户.EditValue.ToString())
                || !String.IsNullOrWhiteSpace(this.barEditItem密码.EditValue.ToString()))
                {
                    NakeSignInDao nakeSignInDao =
                        nakeService.nakeSignIn(
                            this.barEditItem用户.EditValue.ToString().Trim(),
                            this.barEditItem密码.EditValue.ToString().Trim()
                            );
                    if (!String.IsNullOrEmpty(nakeSignInDao.orgId))
                    {
                        this.orgId = nakeSignInDao.orgId;
                        this.barEditItem用户.Enabled = false;
                        this.barEditItem密码.Enabled = false;
                    }
                    else
                    {
                        MessageBox.Show("用户名密码错误");
                    }
                }
                else
                {
                    MessageBox.Show("用户名密码不能为空");
                }
            }
            catch { }
            this.refreshata();
        }
    }
}